<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>

<head>
</head>
<style>
</style>

<body>
	<div id="leg_table"></div>
	<script type="text/html" id="Bar">
			<a class="mui-btn mui-btn-primary edit">编辑</a>
			<a class="mui-btn mui-btn-primary del">删除</a>
		</script>
	<script type="text/javascript">
        	mui('#offCanvasContentScroll').scroll().scrollTo(0,0);
        
        	$(".mui-title").html("角色列表");
        	
        	//接收数据
			var stateList = $.legTable({
				limit: 10,			//默认10
				page:1,				//默认1
				id:"#leg_table",	//绑定id
				url:"/main/getRoleList",
				cols:[
					{field: 'roleName', title: '角色名称'},
		            {field: 'compName', title: '公司'},
		            {field: 'des', title: '备注'},
		            {title: '操作', templet:'#Bar'}
		        ]
			});
			
			//添加
			$("#Add").show();
			$("#Add").on("touchstart",function(e){
				$("#Add").hide();
				url = "/roleAdd/index";
				window.location.href = url;
			})

			//编辑
			$("#leg_table").on("touchstart", ".table-list .edit", function(e){
				let i = $(this).parent('data').attr("value");
				let url = "/roleEdit/index?roleId="+$.data(i).roleId;
				window.location.href = url;
				sessionStorage.setItem("role",JSON.stringify($.data(i)))
		    })
           	
           //删除
          $("#leg_table").on("touchstart", ".table-list .del", function(e){
        	    let i = $(this).parent('data').attr("value");
       	    	mui.confirm('确定删除此角色？','温馨提示',function(e) {
					if (e.index == 1) {
						$.get("/main/deleteRole?roleId="+$.data(i).roleId,function(res){
			           		if (!res.success) {
			           			mui.toast(res.message);
			       			}else{
			       				mui.toast("删除成功");
			       				stateList = $.legTable();
			       			}
			           	})
					}
				})
            })
			
		</script>
</body>

</html>